package cn.edu.ctbu.datajpa01.repository;

import cn.edu.ctbu.datajpa01.domain.Student;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.domain.Pageable;
import java.util.List;

public interface StudentRepository extends JpaRepository<Student,Integer>{

    /**
     * 按名字查询
     * @param name
     * @return
     */
    List<Student> findByNameLike(String name);
    /**
     * 按名字和密码查询
     */
    List<Student> findByNameAndPassword(String name, String password);

    @Query("SELECT t FROM tb_student1 t WHERE substring(t.no, 1, 4) ="+" (SELECT substring(MAX(t2.no), 1, 4)FROM tb_student1 t2 group by substring(t2.no, 1, 4)having count(*)>1)")
    List<Student> findStudentsWithMaxIdPrefix();

    public Page<Student> findAll(Pageable pageable);
    List<Student> findAll();

    public Page<Student> findBySex(Integer sex, Pageable pageable );


}
